Q: How to I create a Mac OS X JNI (Java Native
Interface) library with Project Builder?
A: Project builder does not have a template
project, or a template target for JNI libraries. The
following steps will create a Project Builder target for
building a JNI library for Mac OS X.
- Under the Project Menu, add a new target.
- Select the target template called Library.
- Set the target name to be
lib{libname}.jnilib as
in "libhello.jnilib".
- Select the new target, and then a tab called Build Settings
should appear in the pane next to the target's pane. Select the
Build Settings target.
- Scroll down to the Search paths panel.
- Add the following path to the list of Headers (which is in
the Search paths panel):
/System/Library/Frameworks/JavaVM.framework/Headers
|
- Scroll down to the Expert Build Settings panel.
- In the Expert Build Settings, delete the DYLIB_COMPATIBILITY_VERSION
and the DYLIB_CURRENT_VERSION options. (The Delete
key will delete them.)
- In the Expert Build Settings, change the LIBRARY_STYLE option to BUNDLE.
(Double click in the value column of a build setting to change it.)
- Select the Files tab on the vertical pane to the left of the window.
- Add the Java-generated header files and the native implementations
to the target.
Note:
JNI libraries must be in the path defined by
the Java property "java.library.path" to be loaded with the
System.loadLibrary("libname") method. To extend the
java.library.path, define the environment variable
DYLD_LIBRARY_PATH with the additional directories.
|
The default value of java.library.path in Mac OS X is:
.:/usr/lib:/usr/lib/java:/lib:/System/Library/
Framworks/JavaVM.framework/Versions/1.3/Libraries
|
Java applications built with Project Builder and
MRJAppBuilder also search for libraries in the Contents/Resources/Java/
folder of the applications bundle.
[Jun 19 2001]
|